#define _CRT_SECURE_NO_WARNINGS 1

#include"stack.h"
#include<stdbool.h>

void TEST1(void)
{
	Stack S;
	StackInit(&S);
	StackPush(&S, 5);
	StackPush(&S, 3);
	StackPush(&S, 4);
	Stackprint(&S);
	StackPop(&S);
	Stackprint(&S);
	printf("%d\n", StackTop(&S));
}


bool isValid(char* s) {
    Stack S;
    StackInit(&S);
    int len = strlen(s);
    int i = 0;
    for (i = 0; i < len; i++)
    {
        if (s[i] == '[' || s[i] == '(' || s[i] == '{')
        {
            StackPush(&S, s[i]);
        }
        else
        {
            if (StackEmpty(&S))
            {
                StackDestroy(&S);
                return false;
            }
            char top = StackTop(&S);
            StackPop(&S);
            if ((s[i] == '}' && top != '{') ||
                (s[i] == ')' && top != '(') ||
                (s[i] == ']' && top != '['))
            {
                StackDestroy(&S);
                return false;
            }
        }
    }
    bool ret = StackEmpty(&S);
    StackDestroy(&S);
    return ret;
}
int main()
{
	char arr[] = { "()[]{}" };
    isValid(arr);
	return 0;
}

